package main

import (
	"GinTemplate/conf"
	"GinTemplate/internal/dao/db"
	"GinTemplate/pkg/httpServer"
	"GinTemplate/router"
	"GinTemplate/utils/log"
	"fmt"
)

func main() {
	// 初始化配置
	conf.InitConfig()

	// 创建路由,挂载中间件
	engin := router.NewGinRouter(
		log.LoggerToFile1(),
	)

	//初始化MySQL
	db.InitMysql()

	//注册路由
	router.RegisterRouter(engin)

	//创建http server
	server := httpServer.NewServer(conf.Cfg.Server.Host, conf.Cfg.Server.Port, engin)

	//启动http server
	httpServer.ListenAndServe(server)

	//等待服务退出
	httpServer.WaitForShutdown(server, func() {
		fmt.Println("Close mysql connection.")
	})
}
